package com.crud.config;

import lombok.Data;
import org.springframework.http.HttpStatus;

@Data
public class ResultVo {
    private Integer code;
    private String msg;
    private Object data;
    public ResultVo(Object data){
        this.data = data;
    }
    public ResultVo(String msg, Object data){
        this.msg = msg;
        this.data = data;
    }

    public ResultVo(Integer code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public ResultVo(Integer code, String msg, Object data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }
    public static ResultVo success(String msg){
        return new ResultVo(HttpStatus.OK.value(), msg);
    }
    public static ResultVo success(Object data){
        return new ResultVo(HttpStatus.OK.value(), "操作成功", data);
    }
    public static ResultVo success(String msg, Object data){
        return new ResultVo(HttpStatus.OK.value(), msg, data);
    }

    public static ResultVo failure(String msg){
        return new ResultVo(HttpStatus.INTERNAL_SERVER_ERROR.value(), msg);
    }
    public static ResultVo failure(Object data){
        return new ResultVo(HttpStatus.INTERNAL_SERVER_ERROR.value(), "操作失败", data);
    }
    public static ResultVo failure(String msg, Object data){
        return new ResultVo(HttpStatus.INTERNAL_SERVER_ERROR.value(), msg, data);
    }
}
